package com.icoding.fw.utils;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;

import com.icoding.fw.modelview.NameDTO;

public class NameDTOParse {
	private static NameDTOParse nameDTOParse;

	private NameDTOParse() {
	}

	public static NameDTOParse init() {
		if (nameDTOParse == null) {
			nameDTOParse = new NameDTOParse();
		}
		return nameDTOParse;
	}

	@SuppressWarnings("rawtypes")
	public List<String> getNameFieldAnnotation(Class clazz) {
		List<String> listStrings = new ArrayList<String>();
		Field[] allFields = clazz.getDeclaredFields();
		for (Field field : allFields) {
			if (Modifier.isPrivate(field.getModifiers())) {
				NameDTO nameDTO = field.getAnnotation(NameDTO.class);
				if (nameDTO != null) {
					listStrings.add(nameDTO.name());
				}
			}
		}
		return listStrings;
	}
}
